﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using Dynamic_UI_Framework;
using System.ComponentModel.Composition.Hosting;

namespace WPF
{
    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            Boot boot = new Boot(new Setting { PartPath = Environment.CurrentDirectory + "\\Parts", RegionPath = Environment.CurrentDirectory + "\\Regions", UITreePath="ui.xml" });
            boot.Run();
        }
    }
    public class Boot : MefBootstrapper
    {
        public Boot(Setting setting) : base(setting) { }

        protected override void ConfigureAggregateCatalog()
        {
            base.ConfigureAggregateCatalog();
            this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(this.GetType().Assembly));
        }

        public override void Run(bool runWithDefaultConfiguration)
        {
            base.Run(runWithDefaultConfiguration);

            CompositionContainer c = this.Container;
            foreach (var item in c.Catalog.Parts)
            {
                Console.WriteLine("");
                foreach (var mdd in item.Metadata)
                    Console.WriteLine("Part: " + mdd.Key + ":" + mdd.Value);
                foreach (var ed in item.ExportDefinitions)
                {
                    Console.WriteLine("    " + ed.ContractName);
                    foreach (var md in ed.Metadata)
                    {
                        Console.WriteLine("    " + md.Key + " : " + md.Value);
                    }
                }
            }
        }
    }


}
